<?php
/*********************************************************************************
 * 社会化登录
 *-------------------------------------------------------------------------------
 * 版权所有: CopyRight By yiqiu.org
 * 联系我们: yiqiustudio@gmail.com
 *-------------------------------------------------------------------------------
 * Author:亦秋_小新
 * Dtime:2016-12-26 19:02:41
***********************************************************************************/

require_once(dirname(__file__)."/../../include/qq/qqConnectAPI.php");
require_once(dirname(__file__)."/../../../user/config.php");
$qc = new QC();
$openid = $qc->keysArr['openid'];
$userinfo = $qc->get_user_info();
if($cfg_soft_lang == 'gb2312')
{
	$userinfo['nickname'] = utf82gb($userinfo['nickname']);
	$userinfo['gender'] = utf82gb($userinfo['gender']);
}


if($cfg_ml->IsLogin())
{
    ShowMsg('你已经登陆系统，无需重新注册！', '/user');
    exit();
}

$appid = "qq".substr($openid,2,8);
$userid = $appid;
$uname = $userinfo['nickname'];

$memInfo = $dsql->GetOne("SELECT * FROM #@__member WHERE `userid` = '{$userid}'");
$jointime = time();
$logintime = time();
$joinip = GetIP();
$loginip = GetIP();
if(empty($memInfo))
{
	$inQuery = "INSERT INTO `#@__member` (`mtype` ,`userid` ,`uname`  ,`rank` ,
        `matt` ,`face`,`jointime` ,`joinip` ,`logintime` ,`loginip`,`mode`)
       VALUES ('个人','$userid','$userinfo[nickname]','10','0','$userinfo[figureurl_1]','$jointime','$joinip','$logintime','$loginip','qq'); "; 
     if($dsql->ExecuteNoneQuery($inQuery))
     {
			$mid = $dsql->GetLastID();
			//写入默认统计数据
            $membertjquery = "INSERT INTO `#@__member_tj` (`mid`,`article`,`album`,`archives`,`homecount`,`pagecount`,`feedback`,`friend`,`stow`)
                   VALUES ('$mid','0','0','0','0','0','0','0','0'); ";
            $dsql->ExecuteNoneQuery($membertjquery);
    
            //写入默认空间配置数据
            $spacequery = "INSERT INTO `#@__member_space`(`mid` ,`pagesize` ,`matt` ,`spacename` ,`spacelogo` ,`spacestyle`, `sign` ,`spacenews`)
                    VALUES('{$mid}','10','0','{$uname}的空间','','$space','',''); ";
            $dsql->ExecuteNoneQuery($spacequery);
			
            $cfg_ml->PutLoginInfo($mid);
            if(method_exists($cfg_ml,"DelCache") == TRUE) $cfg_ml->DelCache($mid);
            ShowMsg("成功登录，5秒钟后转向系统主页...","/user",0,2000);
            exit;
      }
}else{
	
	$cfg_ml->PutLoginInfo($memInfo['mid']);
    if(method_exists($cfg_ml,"DelCache") == TRUE) $cfg_ml->DelCache($cfg_ml->M_ID);
    ShowMsg("成功登录，5秒钟后转向系统主页...","/user",0,2000);
    exit;
}